package dmt16.TelemetrySuit.Utils
{
	public class NMEASentence
	{
		public static const MILES_PER_HOUR:Number=1.150769;
		public static const METRES_PER_SECOND:Number=0.514444;
		public static const KILOMETRES_PER_HOUR:Number=1.851984;
		
		public function NMEASentence(sentence:String)
		{
			var fields:Array=sentence.split(",");
			_speed=Number(fields[6]);
			var y:Number=Number("20"+String(fields[8]).substr(4,2));
			var m:Number=Number(String(fields[8]).substr(2,2));
			var d:Number=Number(String(fields[8]).substr(0,2));
			var h:Number=Number(String(fields[0]).substr(0,2));
			var min:Number=Number(String(fields[0]).substr(2,2));
			var s:Number=Number(String(fields[0]).substr(4,2));
			_dateTime=new Date(y,m,d,h,min,s);
			_position=new GPSpoint(fields[2],fields[3],fields[4],fields[5]);
		}
		
		private var _dateTime:Date;
		public function get dateTime():Date
		{
			return _dateTime;
		}
		
		private var _position:GPSpoint;
		public function get position():GPSpoint
		{
			return _position;
		}

		
		private var _speed:Number;
		public function speed(scale:Number=METRES_PER_SECOND):Number
		{
			return _speed*scale;
		}
	}
}